﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CMN.BLL;
using CMN.Common;
using CMN.Entity;
using CMN.Models.Interfaces;
namespace CMN.Models
{
    /// <summary>
    /// 用户角色表Service
    /// </summary>
    public class Sys_UserRolesService: IDataService<Sys_UserRolesEntity>
    {
        /// <summary>
        /// 新增用户角色表
        /// </summary>
        /// <param name="Sys_UserRolesEntity"></param>
        /// <returns>bool</returns>
        public string Insert(Sys_UserRolesEntity sys_userrolesEntity)
        {
            sys_userrolesEntity.DataTable_Action = DataTableAction.Insert;
            BLLHelper bll = new BLLHelper();
            if (bll.Sys_UserRolesInsertUpdateDelete(sys_userrolesEntity) > 0)
            {
                return "";
            }
            else
            {
                return "失败";
            }
        }

        /// <summary>
        /// 返回用户角色表查询列表
        /// </summary>
        /// <param name="qp"></param>
        /// <param name="count">查询总个数</param>
        /// <returns>List</returns>
        public List<Sys_UserRolesEntity> List(QueryParam qp,out int count)
        {
            BLLHelper bll = new BLLHelper();
            return bll.Sys_UserRolesList(qp, out count);
        }

        /// <summary>
        /// 更新用户角色表
        /// </summary>
        /// <param name="Sys_UserRoles"></param>
        /// <returns>bool</returns>
        public string Update(Sys_UserRolesEntity sys_userrolesEntity)
        {
            sys_userrolesEntity.DataTable_Action = DataTableAction.Update;
            BLLHelper bll = new BLLHelper();
            if (bll.Sys_UserRolesInsertUpdateDelete(sys_userrolesEntity) > 0)
            {
                return "";
            }
            else
            {
                return "失败";
            }
        }

        /// <summary>
        /// 删除用户角色表
        /// </summary>
        /// <param name="Sys_UserRoles"></param>
        /// <returns>bool</returns>
        public string Delete(Sys_UserRolesEntity sys_userrolesEntity)
        {
            sys_userrolesEntity.DataTable_Action = DataTableAction.Delete;
            BLLHelper bll = new BLLHelper();
            if (bll.Sys_UserRolesInsertUpdateDelete(sys_userrolesEntity) > 0)
            {
                return "";
            }
            else
            {
                return "失败";
            }
        }

        /// <summary>
        /// 批量删用户角色表
        /// </summary>
        /// <param name="idList">删除id列表  2_8_9_45</param>
        /// <returns>bool</returns>
        public string DeleteList(string idList)
        {
            int userId = Utils.StringToInt(idList, 0);
            try
            {
                BLLHelper bll = new BLLHelper();
                bll.Sys_UserRolesDelUserId(userId);
                 return "" ;
           
               
            
            }
            catch (Exception ex)
            {
           
                return "失败";
            
            }
        }

        /// <summary>
        /// 返回单个用户角色表
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Sys_UserRolesEntity</returns>
        public Sys_UserRolesEntity Look(int id)
        {
            QueryParam qp = new QueryParam();
            qp.PageIndex = 1;
            qp.PageSize = 1;
            qp.Where = string.Concat("R_RoleId=", id.ToString());
            int recordNum = 0;
            BLLHelper bll = new BLLHelper();
            List<Sys_UserRolesEntity> userRoles = bll.Sys_UserRolesList(qp, out recordNum);
            if (userRoles.Count > 0)
            {
                return userRoles[0];
            }
            return null;
        }
    }
}
